import { list as baseQuestionList } from '@/api/hmmm/questions.js'
const app = {
  state: {
    name: '',
    baseList: [],//基础题库列表数据
    baseCount: 0,//基础题库总条数
  },
  mutations: {
    SET_NAME: (state, name) => {
      state.name = name
    },
    updateBaseList(state, option) {
      state.baseList = option.baseList
      state.baseCount = option.baseCount
    }
  },
  actions: {
    setName({ commit }, userInfo) {
      const username = userInfo.username.trim()
      return new Promise((resolve, reject) => {
        commit('SET_NAME', username)
        resolve()
      })
    },
    async getBaseList(context) {
      const { data: res } = await baseQuestionList()
      const baseList = res.items
      const baseCount = res.counts
      context.commit('updateBaseList', { baseList, baseCount })
    }
  }
}

export default app
